home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Communication / NewsBase / Source / IDataGroupBrowser.m < prev    next >
Text File  |  1993-01-12  |  5KB  |  188 lines

  1. /*$Copyright:
  2.  * Copyright (C) 1992.5.22. Recruit Co.,Ltd. 
  3.  * Institute for Supercomputing Research
  4.  * All rights reserved.
  5.  * NewsBase  by ISR, Kazuto MIYAI, Gary ARAKAKI, Katsunori SUZUKI, Kok-meng Lue
  6.  *
  7.  * You may freely copy, distribute and reuse the code in this program under 
  8.  * following conditions.
  9.  * - to include this notice in the source code, if it is to be distributed 
  10.  *   with source code.
  11.  * - to add the file named "COPYING" within the code, which shall include 
  12.  *   GNU GENERAL PUBLIC LICENSE(*).
  13.  * - to display an acknowledgement in binary code as follows: "This product
  14.  *   includes software developed by Recruit Co.,Ltd., ISR."
  15.  * - to display a notice which shall state that the users may freely copy,
  16.  *   distribute and reuse the code in this program under GNU GENERAL PUBLIC
  17.  *   LICENSE(*)
  18.  * - to indicate the way to access the copy of GNU GENERAL PUBLIC LICENSE(*)
  19.  *
  20.  *   (*)GNU GENERAL PUBLIC LICENSE is stored in the file named COPYING
  21.  * 
  22.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  23.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  24.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  25. $*/
  26. /* IDataGroupBrowser.m */
  27. #import <appkit/NXBrowser.h>
  28. #import <appkit/Matrix.h>
  29. #import <appkit/Text.h>
  30. #import <libc.h>
  31. #import <strings.h>
  32. #import "IDataGroupBrowser.h"
  33. #import "IItemHeaderBrowser.h"
  34. #import "INXBrowserCellWithLinkedObject.h"
  35. #import "INntpIO.h"
  36. #import "INewsgroupInfoD.h"
  37. #import "ITreeNodeD.h"
  38. #import "errdebug.h"
  39. #import "data_types.h"
  40.  
  41. #define     MAXVISIBLECOL         4
  42. #define     MINCOLWIDTH        80
  43.  
  44. @implementation IDataGroupBrowser
  45.  
  46. - initFrame:(NXRect *)frameRect
  47. {
  48.     [super initFrame:frameRect];
  49.     [self setMinColumnWidth:MINCOLWIDTH];
  50.     [self setMaxVisibleColumns:MAXVISIBLECOL];
  51.     [self acceptArrowKeys:YES andSendActionMessages:NO];
  52.     
  53.     iKeyRecord[0] = '\0';
  54.     return self;
  55. }
  56.  
  57. /*
  58.     The target object and action message of newsBrowser is IDataGroupBrowser
  59.     and NewsGroupBrowserLeafHandler.  I.e., NewsGroupBrowserLeafHandler is
  60.     called when a newsgroup is selected.
  61. */
  62.  
  63. - (void)leafHandler:sender
  64. {
  65.     id        selectedCell;
  66.     id        node;
  67.     id        itemHeaderslist;
  68.     // valuables for routine of updating cells
  69.     id        cellList, bcell, linkednode, groupInfo;
  70.     int        i;
  71.  
  72.     iKeyRecord[0] = '\0';        // reset key record
  73.     [window makeFirstResponder:self];    // set first responder to self
  74.     
  75.     selectedCell = [[self matrixInColumn:[self lastColumn]] selectedCell];
  76.  
  77.     if ([selectedCell isLeaf]) {
  78.         node = [selectedCell node];
  79.         itemHeaderslist = [iIOmodule itemHeadersOf:node];
  80.     
  81.     // this part is for updating unmarked image on each cell
  82.     //    but,... it's very timecomsuming.
  83.     DBG(10,fprintf(stderr," +++ update cells in browser +++\n"));
  84.     cellList = [[self matrixInColumn:[self lastColumn]] cellList];
  85.     for (i=0; bcell=[cellList objectAt:i]; ++i) {
  86.         if ([bcell isLeaf] && (linkednode=[bcell node]) != nil) {
  87.         if ((groupInfo=[[linkednode linkedData] dataForKey:GROUPINFO])
  88.                                 != nil) {
  89.             DBG(10,fprintf(stderr,"  newsgroup = %s\n",
  90.                     (char *)[groupInfo infoForKey:"Newsgroups"]));
  91.             if ([groupInfo isAllArticleMarked] == NO) {
  92.             [bcell setImage:[NXImage findImageNamed:UNREADMARK]];
  93.             DBG(10,fprintf(stderr,"    ooo unread mark ooo\n"));
  94.             } else {
  95.             [bcell setImage:nil];
  96.             DBG(10,fprintf(stderr,"    xxx nil xxx\n"));
  97.             }
  98.         }
  99.         }
  100.     }
  101.  
  102.     [self displayColumn:[self lastColumn]]; // update cell
  103.     DBG(10,fprintf(stderr," --- update cells in browser ---\n"));
  104.     
  105.     [iItemRepUIF setRootListnode:itemHeaderslist];
  106.         [iItemRepUIF loadColumnZero];
  107.     } else {
  108.     [iItemRepUIF setRootListnode:nil];
  109.         [iItemRepUIF loadColumnZero];
  110.     }
  111. }
  112.  
  113. - directoryHandler:node
  114. {
  115.     // called from ITreeBrowser
  116.     // return the list of nodes, the list will be used in ITReeBrowser
  117.     // to fill up the cells under this directory
  118.  
  119.     iKeyRecord[0] = '\0';        // reset key record
  120.     [window makeFirstResponder:self];    // set first responder to self
  121.     
  122.     return [iIOmodule subDirectoryOf:node];
  123. }
  124.  
  125. - setONewsgroupScroll:anObject
  126. {
  127.     oNewsgroupScroll = anObject;
  128.     [self setAuxAgent:oNewsgroupScroll];
  129.     [self setAuxAction:@selector(newsgroupClicked:)];
  130.     return self;
  131. }
  132.  
  133. - (BOOL)acceptsFirstResponder
  134. {
  135.     return YES;
  136. }
  137.  
  138. - keyDown:(NXEvent *)theEvent
  139. {
  140.     int        ilen;
  141.     unsigned int    ch;
  142.     
  143.     // CR: perform click
  144.     // alpha numeric: select matched sell
  145.     
  146.     DBG(1,fprintf(stderr,"  keydown"));
  147.     if ((ch=(theEvent->data).key.charCode) == NX_CR) {
  148.     // "Return" key pressed
  149.     DBG(1,fprintf(stderr,"  NX_CR"));
  150.     // click selected cell
  151.     [[self matrixInColumn:[self selectedColumn]] sendAction];
  152.     iKeyRecord[0]='\0';    // reset key record
  153.     return self;
  154.     }
  155.     if (ch == 0x15) {
  156.     // produced by 'control+u'
  157.     // set path to root
  158.     iKeyRecord[0] = pathSeparator;
  159.     iKeyRecord[1] = '\0';
  160.     [self setPath:iKeyRecord];
  161.     iKeyRecord[0] = '\0';        // reset iKeyRecord
  162.     return self;
  163.     }
  164.  
  165.     // set path for browser
  166.     if ((theEvent->data).key.charSet == NX_ASCIISET &&
  167.             0x20 <= ch && ch <= 0x7f &&
  168.         (ilen=strlen(iKeyRecord)) <= 31) {
  169.     if (ch == NX_DELETE) {
  170.         if ((ilen = ilen - 1) < 0) {
  171.         ilen = 0;
  172.         }
  173.         iKeyRecord[ilen] = '\0';
  174.     } else {
  175.         iKeyRecord[ilen] = ch;
  176.         iKeyRecord[ilen+1] = '\0';
  177.     }
  178.     DBG(1,fprintf(stderr,"  iKeyRecord=%s\n", iKeyRecord));
  179.     [self setPath:iKeyRecord];
  180.     return self;
  181.     }
  182.     
  183.     // handle arrow keys in super class
  184.     return ([super keyDown:theEvent]);
  185. }
  186.  
  187. @end
  188.